/*
 * @Author: your name
 * @Date: 2024-04-19 10:30:23
 * @LastEditTime: 2024-04-19 10:31:09
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \.leetcode\104.二叉树的最大深度.cpp
 */
/*
 * @lc app=leetcode.cn id=104 lang=cpp
 *
 * [104] 二叉树的最大深度
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    int maxDepth(TreeNode* root) {
        if(root == nullptr){
            return 0;
        }
        queue<TreeNode*> que;
        int depth = 0;
        que.push(root);
        while(!que.empty()){
            int size = que.size();
            depth++;
            for(int i = 0; i < size; i++){
                TreeNode* tmp_node = que.front();
                que.pop();
                if(tmp_node->left) que.push(tmp_node->left);
                if(tmp_node->right) que.push(tmp_node->right);
            }
        }
        return depth;
    }
};
// @lc code=end

